import axios from '../utils/axios'

module.exports = async (ctx) => {
  const key = '5WNBZ-2JYR6-SPUSL-M3WGH-U4KDT-K2FYV'
  const {
    data: {
      status,
      result
    }
  } = await axios.get(`https://apis.map.qq.com/ws/location/v1/ip?callback=showLocation&key=${key}&output=json`)
  if (status === 0) {
    ctx.body = {
      province: result.ad_info.province,
      city: result.ad_info.city
    }
  } else {
    ctx.body = {
      province: '',
      city: ''
    }
  }
}
